<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>" />
<title>Index</title>

<jsp:include page="../header.jsp"></jsp:include>

<script type="text/javascript">
	$(function() {
		$("#addCompany").click(function() {
			showCompanyPanel();
		});

        $('.selectpicker').selectpicker();
	});

	function showCompanyPanel(id, name, admin, type) {
		$("#companyPanel [name='company.id']").val(id);
		$("#companyPanel [name='company.name']").val(name);
		$("#companyPanel [name='company.admin']").val(admin);
        $("#companyPanel [name='company.type']").selectpicker('val', type);
        $("#companyPanel").modal();
	}
</script>
</head>
<body>
	<jsp:include page="../top.jsp"></jsp:include>

	<div class="container theme-showcase" role="main">

		<div class="alert alert-success">
			<h2>施工单位列表</h2>
		</div>
		<div class="well">
			<div>
				<a class="btn btn-success" id="addCompany">添加施工单位</a>
			</div>
		</div>

		<div id="companyList">
			<table class="table table-hover">
				<tr>
					<th>单位名称</th>
					<th>单位类型</th>
					<th>负责人</th>
					<th>项目列表</th>
					<th>操作</th>
				</tr>
				<s:iterator value="companyList" var="d">
					<tr>
						<td><s:property value="#d.name" /></td>
						<td><s:property value="#d.type.getStr()" /></td>
						<td><s:property value="#d.admin" /></td>
						<td><a href="project/listProject?company.id=<s:property value='#d.id'/>" class="btn btn-primary">项目列表</a></td>
						<td>
							<div class="btn-group" role="group">
								<button type="button" class="btn btn-primary dropdown-toggle"
									data-toggle="dropdown" aria-haspopup="true"
									aria-expanded="false">
									操作 <span class="caret"></span>
								</button>
								<ul class="dropdown-menu">
									<li><a href="javascript:void(0);"
										onclick="showCompanyPanel('<s:property value="#d.id"/>','<s:property value="#d.name"/>','<s:property value="#d.admin"/>','<s:property value="#d.type.toString()"/>');">修改</a></li>
									<li role="separator" class="divider"></li>
									<li><a
										href="company/deleteCompany?company.id=<s:property value='#d.id'/>" onclick="return confirm('确认删除吗？');">删除</a></li>
								</ul>
							</div>
						</td>
					</tr>
				</s:iterator>
			</table>
		</div>
		<div class="modal fade" id="companyPanel" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel" aria-hidden="true">
			<form action="company/saveCompany" method="post">
				<input type="hidden" name="company.id" />
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal"
								aria-label="Close">
								<span aria-hidden="true">&times;</span>
							</button>
							<h4 class="modal-title">施工单位信息</h4>
						</div>
						<div class="modal-body">
							<h4>
								<ul class="list-group">
									<li class="list-group-item"><label> 单位名称 </label> <input
										type="text" class="form-control" name="company.name"
										placeholder="单位名称" /></li>
									<li class="list-group-item"><label> 单位类型 </label><br/>
										<select class="selectpicker" name="company.type" data-live-search="true">
											<option value="SHEJI">设计单位</option>
											<option value="SHIGONG">施工单位</option>
											<option value="JIANLI">监理单位</option>
											<option value="SHENJI">审计单位</option>
											<option value="ZHAOBIAO">招标单位</option>
										</select>
									</li>
									<li class="list-group-item"><label> 负责人 </label> <input
										type="text" class="form-control" name="company.admin"
										placeholder="负责人" /></li>
								</ul>
							</h4>
						</div>
						<div class="modal-footer">
							<button type="submit" class="btn btn-success">保存</button>
							<button type="button" class="btn btn-default"
								data-dismiss="modal">取消</button>
						</div>
					</div>
				</div>
			</form>
		</div>
		<div class="modal fade" id="devicePanel" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
							aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
						<h4 class="modal-title">设备信息</h4>
					</div>
					<div class="modal-body">
						<h4>
							<ul class="list-group">
								<li class="list-group-item"><label> 设备名 </label>
									<p name="device.name"></p></li>
								<li class="list-group-item"><label> 所在房间 </label>
									<p name="device.company.name"></p></li>
								<li class="list-group-item"><label> IP </label>
									<p name="device.ip"></p></li>
								<li class="list-group-item"><label> 端口 </label>
									<p name="device.port"></p></li>
								<li class="list-group-item"><label> 管理员 </label>
									<p name="device.admin.name"></p></li>
								<li class="list-group-item"><label> 描述 </label>
									<p name="device.description"></p></li>
							</ul>
						</h4>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">
							关闭</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>
